﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DelegateTeach
{
    class Enemy
    {
        public int Blood = 1000;
        public void MinusBlood(int attack)
        {
            Blood -= attack;
            Console.WriteLine(Blood);
        }

    }

    class Player
    {
        public delegate void OnAttackDelegate(int attack);
        public OnAttackDelegate OnAttack = null;

        public void DoAOE()
        {
            if (OnAttack != null)
            {
                OnAttack(10);
            }
        }
    }

    public delegate int Calculate(int x, int y);

    public delegate void delegateStart();

    public delegate string mmmyyyy(string content);

    public delegate decimal CalculateArea(decimal height, decimal weight);

    class Program
    {

        static void Main(string[] args)
        {
            // 定义两个方法
            int Mul(int x, int y)
            {
                return x * y;
            }
            int Div(int x, int y)
            {
                return x / y;
            }
            // 实例化委托
            Calculate a = new Calculate(Mul);
            Calculate b = new Calculate(Div);

            var k = a(1, 2);
            var c = b(1, 2);

            Player player = new Player();
            Enemy enemy0 = new Enemy();
            Enemy enemy1 = new Enemy();
            Enemy enemy2 = new Enemy();
            player.OnAttack += enemy0.MinusBlood;
            player.OnAttack += enemy0.MinusBlood;
            player.OnAttack += enemy0.MinusBlood;


            player.DoAOE();

            //delegateStart delegateStart = null;

            //delegateStart += Start1;
            //delegateStart += Start2;
            //delegateStart += Start3;

            //delegateStart();

            CalculateArea squrare = (height, weight) => height * height;// 正方形
            CalculateArea rectangle = (height, weight) => height * weight;// 矩形
            CalculateArea triangle = (height, weight) => height * weight / 2; //三角形

            var squrareArea = squrare(10, 10);// 100
            var rectangleArea = rectangle(19, 10);//190
            var triangleArea = triangle(10, 5);//25

            //mmmyyyy delegateStart1 = new mmmyyyy(Start1);
            //mmmyyyy delegateStart2 = new mmmyyyy(Start2);
            //delegateStart delegateStart3 = new delegateStart(Start3);
            //delegateStart1("aaaa"); delegateStart2("bbbb"); delegateStart3();
        }

        public static string Start1(string content)
        {
            Console.WriteLine(content + ":111111");

            return "1111";
        }

        public static string Start2(string content)
        {
            Console.WriteLine(content + ":222222");
            return "22222";
        }


        public static void Start1()
        {
            Console.WriteLine("111111");
        }

        public static void Start2()
        {
            Console.WriteLine("222222");
        }


        public static void Start3()
        {
            Console.WriteLine("333333");
        }

    }
}
